const getToken =()=>{
    sessionStorage.getItem('token')
}
const state = {
    token:getToken(),
    user:{},
    // 角色列表
    userID:[]
}
const mutations ={

    SET_TOKEN:(state:any,token:string)=>{
        state.token = token
    },
    SET_USER:(state:any,user:{})=>{
        state.user = user
    },
    SET_USERID:(state:any,userid:[])=>{
        console.log(state.userID,'新的值2');
        state.userID.length=0
            state.userID.push(...userid)
        // console.log(state.userID,'vuex的信息');
    }
}

const actions = {
    SET_USERID:({commit}:any,data:[])=>{
        console.log(data,'action data');
        let newData =[]
        for(let i=0;i<data.length;i++){
            const {id,roleName} = data[i]
            newData.push({id,roleName})
        }
        console.log(newData,state.userID,'新的值');
        newData.length==state.userID.length?false:commit('SET_USERID',newData)

            
        
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
  
  